package com.xypower.service.Impl;

import com.xypower.mapper.BookMapper;
import com.xypower.mapper.DiscountMapper;
import com.xypower.pojo.Book;
import com.xypower.pojo.Discount;
import com.xypower.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 类名:
 * 作者:XY
 * 创建时间:2021/11/15-0:46
 * 功能:
 */
@Service
public class BookServiceImpl implements BookService {
    @Autowired
    private BookMapper bookMapper;
    @Autowired
    private DiscountMapper discountMapper;
    @Override
    public List<Book> getAll() {
        List<Book> books = bookMapper.selectByExample(null);
        for (Book book:books){
            Discount discount = discountMapper.selectByPrimaryKey(book.getDisid());
            book.setDiscname(discount.getDiscname());
            //运算折扣后的值
            float price = book.getSaleprice() * discount.getDiscvalue();
            book.setDiscprice(price);
        }
        return books;
    }
}
